from flask import Blueprint, request
from .save_phone_code import SaveCode
import random

app_phone = Blueprint('app_phone',__name__)

@app_phone.route('/verify',methods=['POST'])
def phone():
    '''用户手机号码和短信验证码入库'''
    info = request.form
    phone = info.get('phone')
    pass_word = info.get('pass_word')
    phone_verify_code = random.randint(100000,999999)
    with SaveCode() as SC:
        SC.save(phone,phone_verify_code,pass_word)
    return SaveCode().send_sms()
    
@app_phone.route('/register', methods=['POST'])
def register_verify():
    '''注册信息验证'''
    info = request.form
    phone = info.get('phone')
    pass_word =info.get('pass_word')
    phone_verify_code = info.get('phone_verify_code')
    with SaveCode() as SC:
        result = SC.register(phone,phone_verify_code,pass_word)
    return result


